#!/bin/bash

# == Basic Concepts of Variables == 

# variable syntax: 
#   * must begin with alphabetic character
#   * rest of character can be numbers, letters, underscore
#   * keywords are not allowed to be the name of variables

# using methods: 
#   * don't need to declare it before use a variable. initialization should be in BEGIN Block, that 
#     will be executed only once.
#   * there no data types in awk, wether an awk variable is a number or a string depends on the context
#   
#   * assignment syntax: variable_name=statements

# - basic usage demo -
awk -f ./05_variables_demo.awk ./test_employee_sal.txt
echo -e '\n'



# == Unary Operations ==

# Unary Operations:
#   *  -: negative
#   * ++: self increase
#   * --: self decrease
#   *  +: the number 

# - negative the salary
awk -F, '{print -$4}' ./test_employee_sal.txt
echo -e '\n'

# - print number of bash users.
awk -F ':' '$NF ~ /\/bin\/bash/ {n++}; END {print n}' /etc/passwd
echo -e '\n'



# == Arithmetic Operations == 
#   * +: addition
#   * -: subtraction
#   * *: multiple
#   * /: divition
#   * %: midulo divition

awk -f ./05_arithmetic.awk ./test_items.txt
echo -e '\n'



# == String Operators ==
#   * ' '(space): is a string operator that does string concatenation 

awk -f ./05_string_operator.awk ./test_items.txt
echo -e '\n'



# == Regular Expression Operators ==
#   *  ~: match operators
#   * !~: not match operations

# - print lines where field no.2 contains "Tennis"

echo "# print lines where field no.2 contains 'Tennis' ";
awk -F "," '$2 ~ "Tennis"' ./test_items.txt
echo -e '\n'

echo "# print lines where field no.2 does not contain 'Tennis' "
awk -F "," '$2 !~ "Tennis"' ./test_items.txt
echo -e '\n'



# == Logical Operators == 

#  OP   Description
# * >   ls greater than
# * >=  is grater than or euqal to 
# * <   is less then
# * <=  is less than or equal to 
# * ==  is equal to
# * !=  is not equal to 
# * &&  Logic AND
# * ||  Logic OR

# - match record with id 103
echo "# print the record with id 103"
awk -F "," '$1 == 103' ./test_items.txt
echo -e '\n'

# - match record with cat 'Video'
echo "# print the record with cat video"
awk -F "," '$3 != "Video" {print $2}' ./test_items.txt
echo -e '\n'
